package cn.neusoft.edu.his.demo.controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;

/***
 *  文件上传相关接口
 */
@RestController
@RequestMapping("file")
@CrossOrigin
public class FileController {

    @PostMapping("upload")
    public String upload(MultipartFile file) {
        if(file.isEmpty()){
            return "文件为空";
        }
        String fileName = file.getOriginalFilename();
        //把前端的文件封装为有个文件对象
        File f = new File("E:/upload/"+file.getOriginalFilename());
        //创建字节流
        try {
            byte[]  arr=file.getBytes();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            file.transferTo(f);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "E:/upload/"+fileName;
   }



}
